
 package com.ami.vmedia.gui;
 
 import com.ami.iusb.IUSBRedirSession;
 import com.ami.kvm.jviewer.Debug;
 import com.ami.kvm.jviewer.JViewer;
 import com.ami.kvm.jviewer.gui.JVToolBar;
 import com.ami.kvm.jviewer.gui.JViewerApp;
 import com.ami.kvm.jviewer.gui.LocaleStrings;
 import com.ami.kvm.jviewer.gui.WindowFrame;
 import com.ami.vmedia.VMApp;
 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
 import java.net.URL;
 import java.util.HashMap;
 import javax.swing.BorderFactory;
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
 import javax.swing.JTable;
 import javax.swing.border.Border;
 import javax.swing.border.TitledBorder;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 public class VMPane
   extends JPanel
 {
   public static final String CD_DEV_CTRL_PANEL_KEY = "CD_DEV_CTRL_PANEL_";
   public static final String FD_DEV_CTRL_PANEL_KEY = "FD_DEV_CTRL_PANEL_";
   public static final String HD_DEV_CTRL_PANEL_KEY = "HD_DEV_CTRL_PANEL_";
   private StatusTable cdStatusTable;
   private StatusTable fdStatusTable;
   private StatusTable hdStatusTable;
   private StatusTabPanel statusTabPanel;
   private JTabbedPane vmDevicePane;
   private int numCD;
   private int numFD;
   private int numHD;
   private HashMap<String, Object> deviceControlPanelMap;
   
   public VMPane()
   {
     initializeVMPane();
   }
   
 
   public void initializeVMPane()
   {
     this.deviceControlPanelMap = new HashMap();
     VMApp.getInstance().createIUSBRedirectionSession();
     this.numCD = VMApp.getInstance().getNumCD();
     this.numFD = VMApp.getInstance().getNumFD();
     this.numHD = VMApp.getInstance().getNumHD();
     setSize(VMApp.getWidth(), VMApp.getHeight());
     constructUI();
     setVisible(true);
     VMApp.getInstance().initDeviceDetector();
     VMApp.getInstance().initRedirectionStatusMonitor();
   }
   
 
   public void constructUI()
   {
     if (getComponentCount() > 0)
       removeAll();
     setLayout(new GridBagLayout());
     
     GridBagConstraints localGridBagConstraints = new GridBagConstraints();
     localGridBagConstraints.fill = 1;
     localGridBagConstraints.weightx = 1.0D;
     localGridBagConstraints.weighty = 1.0D;
     createDevicePane();
     add(this.vmDevicePane, localGridBagConstraints);
   }
   
 
 
 
 
 
 
 
   private JScrollPane createControlScrollPane(int paramInt)
   {
     int i = 0;
     String str1 = "";
     
     JPanel localJPanel = new JPanel(new GridBagLayout());
     DeviceControlPanel localDeviceControlPanel = null;
     GridBagConstraints localGridBagConstraints = new GridBagConstraints();
     Border localBorder = BorderFactory.createLoweredBevelBorder();
     TitledBorder localTitledBorder = BorderFactory.createTitledBorder(localBorder, LocaleStrings.getString("AK_1_VMP"), 0, 1);
     
 
 
 
     localGridBagConstraints.fill = 2;
     localGridBagConstraints.insets = new Insets(10, 10, 5, 10);
     localGridBagConstraints.gridx = 0;
     localGridBagConstraints.gridwidth = 1;
     localGridBagConstraints.gridheight = 1;
     localGridBagConstraints.weightx = 1.0D;
     switch (paramInt) {
     case 0: 
       i = this.numCD;
       str1 = "CD_DEV_CTRL_PANEL_";
       break;
     case 1: 
       i = this.numFD;
       str1 = "FD_DEV_CTRL_PANEL_";
       break;
     case 2: 
       i = this.numHD;
       str1 = "HD_DEV_CTRL_PANEL_";
       break;
     default: 
       i = 0;
     }
     
     for (int j = 0; j < i; j++) {
       String str2 = str1;
       localGridBagConstraints.gridy = j;
       str2 = str2 + j;
       localDeviceControlPanel = new DeviceControlPanel(paramInt, j);
       this.deviceControlPanelMap.put(str2, localDeviceControlPanel);
       
       localJPanel.add(localDeviceControlPanel, localGridBagConstraints);
     }
     JScrollPane localJScrollPane = new JScrollPane(localJPanel, 20, 30);
     
     localJScrollPane.setMaximumSize(new Dimension(VMApp.getWidth(), 100));
     localJScrollPane.setBorder(localTitledBorder);
     return localJScrollPane;
   }
   
 
   private void createDevicePane()
   {
     this.vmDevicePane = new JTabbedPane();
     this.statusTabPanel = new StatusTabPanel();
     this.vmDevicePane.addTab(formatTabTitle(LocaleStrings.getString("AK_3_VMP")), getImageIcon("DVD_tab.png"), createVMDeviceTabPanel(0));
     
     this.vmDevicePane.addTab(formatTabTitle(LocaleStrings.getString("AK_4_VMP")), getImageIcon("FD_tab.png"), createVMDeviceTabPanel(1));
     
     this.vmDevicePane.addTab(formatTabTitle(LocaleStrings.getString("AK_5_VMP")), getImageIcon("HD_tab.png"), createVMDeviceTabPanel(2));
     
     this.vmDevicePane.addTab(formatTabTitle(LocaleStrings.getString("AK_6_VMP")), getImageIcon("status.png"), this.statusTabPanel);
     
 
     updateDeviceControls(0, JViewer.isCdServiceEnabled());
     updateDeviceControls(1, JViewer.isFdServiceEnabled());
     updateDeviceControls(2, JViewer.isHdServiceEnabled());
     
     this.vmDevicePane.addChangeListener(new ChangeListener()
     {
       public void stateChanged(ChangeEvent paramAnonymousChangeEvent) {
         JViewerApp.getInstance().setSelectedVMTab(VMPane.this.vmDevicePane.getSelectedIndex());
         
         VMPane.this.showMessageForSelectedTab(VMPane.this.vmDevicePane.getSelectedIndex());
       }
     });
     
     if (!JViewer.isVMApp()) {
       this.vmDevicePane.setSelectedIndex(JViewerApp.getInstance().getSelectedVMTab());
     }
   }
   
 
 
 
   private String formatTabTitle(String paramString)
   {
     String str = "<html><body leftmargin=15 topmargin=8 marginwidth=10 marginheight=6>" + paramString + "</body></html>";
     
     return str;
   }
   
 
 
 
 
   public ImageIcon getImageIcon(String paramString)
   {
     URL localURL = null;
     ImageIcon localImageIcon = null;
     try
     {
       localURL = JViewer.class.getResource("res/" + paramString);
     } catch (Exception localException1) {
       Debug.out.println(localException1);
     }
     
     if (localURL != null) {
       try {
         localImageIcon = new ImageIcon(localURL);
       } catch (Exception localException2) {
         Debug.out.println(localException2);
       }
     }
     return localImageIcon;
   }
   
 
 
 
 
 
 
   private JPanel createVMDeviceTabPanel(int paramInt)
   {
     GridBagConstraints localGridBagConstraints = new GridBagConstraints();
     JPanel localJPanel = new JPanel(new GridBagLayout());
     
     localGridBagConstraints.insets = new Insets(0, 0, 2, 0);
     localGridBagConstraints.gridx = 0;
     localGridBagConstraints.fill = 2;
     localGridBagConstraints.ipady = 400;
     localGridBagConstraints.gridy = 0;
     localGridBagConstraints.gridwidth = 1;
     localGridBagConstraints.gridheight = 1;
     localGridBagConstraints.weightx = 1.0D;
     localGridBagConstraints.weighty = 0.95D;
     localJPanel.add(createControlScrollPane(paramInt), localGridBagConstraints);
     localGridBagConstraints.insets = new Insets(15, 0, 0, 0);
     localGridBagConstraints.ipady = 75;
     localGridBagConstraints.gridy = 1;
     localGridBagConstraints.weighty = 0.05D;
     JScrollPane localJScrollPane = createStatusScrollPane(paramInt);
     localJPanel.add(localJScrollPane, localGridBagConstraints);
     updateFreeDeviceStatus(paramInt);
     return localJPanel;
   }
   
 
 
 
 
 
 
 
 
 
   private JScrollPane createStatusScrollPane(int paramInt)
   {
     Border localBorder = BorderFactory.createEtchedBorder();
     TitledBorder localTitledBorder = null;
     String str = "";
     StatusTable localStatusTable = new StatusTable(paramInt);
     JScrollPane localJScrollPane = new JScrollPane(localStatusTable.getStatusTable(), 20, 30);
     
 
     switch (paramInt) {
     case 0: 
       this.cdStatusTable = localStatusTable;
       str = LocaleStrings.getString("AK_3_VMP") + " " + LocaleStrings.getString("AK_2_VMP");
       break;
     case 1: 
       this.fdStatusTable = localStatusTable;
       str = LocaleStrings.getString("AK_4_VMP") + " " + LocaleStrings.getString("AK_2_VMP");
       break;
     case 2: 
       this.hdStatusTable = localStatusTable;
       str = LocaleStrings.getString("AK_5_VMP") + " " + LocaleStrings.getString("AK_2_VMP");
     }
     
     localTitledBorder = BorderFactory.createTitledBorder(localBorder, str, 0, 1);
     
 
 
 
     localJScrollPane.setBorder(localTitledBorder);
     return localJScrollPane;
   }
   
 
 
 
 
 
 
 
 
   public DeviceControlPanel getDeviceControlPanel(int paramInt1, int paramInt2)
   {
     DeviceControlPanel localDeviceControlPanel = null;
     switch (paramInt1) {
     case 0: 
       localDeviceControlPanel = (DeviceControlPanel)this.deviceControlPanelMap.get("CD_DEV_CTRL_PANEL_" + paramInt2);
       break;
     case 1: 
       localDeviceControlPanel = (DeviceControlPanel)this.deviceControlPanelMap.get("FD_DEV_CTRL_PANEL_" + paramInt2);
       break;
     case 2: 
       localDeviceControlPanel = (DeviceControlPanel)this.deviceControlPanelMap.get("HD_DEV_CTRL_PANEL_" + paramInt2);
     }
     
     return localDeviceControlPanel;
   }
   
   public JTable getCDStatusTable() {
     return this.cdStatusTable.getStatusTable();
   }
   
   public JTable getFDStatusTable() { return this.fdStatusTable.getStatusTable(); }
   
 
   public JTable getHDStatusTable() { return this.hdStatusTable.getStatusTable(); }
   
   public void updateDeviceControlPanel(int paramInt, String[] paramArrayOfString) {
     DeviceControlPanel localDeviceControlPanel = null;
     int i; switch (paramInt) {
     case 0: 
       for (i = 0; i < VMApp.getInstance().getNumCD(); i++) {
         localDeviceControlPanel = (DeviceControlPanel)this.deviceControlPanelMap.get("CD_DEV_CTRL_PANEL_" + i);
         updateDevicePanel(paramInt, i, paramArrayOfString, localDeviceControlPanel);
       }
       break;
     case 1: 
       for (i = 0; i < VMApp.getInstance().getNumFD(); i++) {
         localDeviceControlPanel = (DeviceControlPanel)this.deviceControlPanelMap.get("FD_DEV_CTRL_PANEL_" + i);
         updateDevicePanel(paramInt, i, paramArrayOfString, localDeviceControlPanel);
       }
       break;
     case 2: 
       for (i = 0; i < VMApp.getInstance().getNumHD(); i++) {
         localDeviceControlPanel = (DeviceControlPanel)this.deviceControlPanelMap.get("HD_DEV_CTRL_PANEL_" + i);
         updateDevicePanel(paramInt, i, paramArrayOfString, localDeviceControlPanel);
       }
     }
     
   }
   
   private void updateDevicePanel(int paramInt1, int paramInt2, String[] paramArrayOfString, DeviceControlPanel paramDeviceControlPanel)
   {
     DevicePanel localDevicePanel = null;
     paramDeviceControlPanel.getInstanceScrollPane().setViewportView(null);
     localDevicePanel = new DevicePanel(paramArrayOfString, paramInt1, paramInt2);
     paramDeviceControlPanel.getInstanceScrollPane().setViewportView(localDevicePanel);
     paramDeviceControlPanel.setDevicePanel(localDevicePanel);
     paramDeviceControlPanel.updateDeviceControlPanel();
     paramDeviceControlPanel.revalidate();
     paramDeviceControlPanel.repaint();
   }
   
   public void physicalDriveChangeState(int paramInt1, int paramInt2, String paramString, boolean paramBoolean)
   {
     int i = 0;
     DeviceControlPanel localDeviceControlPanel = null;
     String str = null;
     switch (paramInt1) {
     case 0: 
       i = VMApp.getInstance().getNumCD();
       str = "CD_DEV_CTRL_PANEL_";
       break;
     case 1: 
       i = VMApp.getInstance().getNumFD();
       str = "FD_DEV_CTRL_PANEL_";
       break;
     case 2: 
       i = VMApp.getInstance().getNumHD();
       str = "HD_DEV_CTRL_PANEL_";
     }
     
     for (int j = 0; j < i; j++) {
       if (j != paramInt2)
       {
         if (VMApp.getInstance().getIUSBRedirSession().getDeviceRedirStatus(paramInt1, j) != 1) {
           localDeviceControlPanel = (DeviceControlPanel)this.deviceControlPanelMap.get(str + j);
           localDeviceControlPanel.getDevicePanel().updatePhysicalDeviceState(paramInt1, paramString, paramBoolean);
         } }
     }
   }
   
   public void updateJVToolbar(int paramInt) {
     int i = 0;
     int j = 0;
     JButton localJButton = null;
     String str1 = null;
     String str2 = null;
     String str3 = null;
     String str4 = null;
     switch (paramInt) {
     case 0: 
       i = VMApp.getInstance().getNumCD();
       localJButton = JViewerApp.getInstance().getM_wndFrame().getToolbar().getCDBtn();
       str1 = "CD.png";
       str3 = LocaleStrings.getString("G_20_VMD");
       str2 = "CDR.png";
       str4 = LocaleStrings.getString("G_21_VMD");
       break;
     case 1: 
       i = VMApp.getInstance().getNumFD();
       localJButton = JViewerApp.getInstance().getM_wndFrame().getToolbar().getFloppyBtn();
       str1 = "Floppy.png";
       str3 = LocaleStrings.getString("G_22_VMD");
       str2 = "FloppyR.png";
       str4 = LocaleStrings.getString("G_23_VMD");
       break;
     case 2: 
       i = VMApp.getInstance().getNumHD();
       localJButton = JViewerApp.getInstance().getM_wndFrame().getToolbar().getHardddiskBtn();
       str1 = "HD.png";
       str3 = LocaleStrings.getString("G_24_VMD");
       str2 = "HDR.png";
       str4 = LocaleStrings.getString("G_25_VMD");
     }
     
     for (int k = 0; k < i; k++) {
       if (VMApp.getInstance().getIUSBRedirSession().getDeviceRedirStatus(paramInt, k) == 1)
       {
         j = 1;
         break;
       }
     }
     if (j != 0) {
       localJButton.setIcon(getImageIcon(str2));
       localJButton.setToolTipText(str4);
     }
     else {
       localJButton.setIcon(getImageIcon(str1));
       localJButton.setToolTipText(str3);
     }
   }
   
   public void updateDeviceStatusTable(int paramInt1, int paramInt2, boolean paramBoolean) { IUSBRedirSession localIUSBRedirSession = VMApp.getInstance().getIUSBRedirSession();
     JTable localJTable = null;
     String str1 = LocaleStrings.getString("AL_8_ST");
     String str2 = LocaleStrings.getString("AL_8_ST");
     switch (paramInt1) {
     case 0: 
       localJTable = getCDStatusTable();
       if (paramBoolean) {
         str1 = LocaleStrings.getString("AL_5_ST") + " : " + localIUSBRedirSession.getCDInstanceNumber(paramInt2);
       }
       break;
     case 1: 
       localJTable = getFDStatusTable();
       if (paramBoolean) {
         str1 = LocaleStrings.getString("AL_6_ST") + " : " + localIUSBRedirSession.getFDInstanceNumber(paramInt2);
       }
       break;
     case 2: 
       localJTable = getHDStatusTable();
       if (paramBoolean) {
         str1 = LocaleStrings.getString("AL_7_ST") + " : " + localIUSBRedirSession.getHDInstanceNumber(paramInt2);
       }
       break;
     }
     if (paramBoolean) {
       str2 = localIUSBRedirSession.getDeviceRedirSource(paramInt1, paramInt2);
     } else {
       str2 = LocaleStrings.getString("AL_8_ST");
       str1 = LocaleStrings.getString("AL_8_ST");
     }
     localJTable.setValueAt(str1, paramInt2, 1);
     localJTable.setValueAt(str2, paramInt2, 2);
   }
   
 
   public void updateFreeDeviceStatus(int paramInt)
   {
     int i = 0;
     int j = 0;
     int k = 0;
     IUSBRedirSession localIUSBRedirSession = VMApp.getInstance().getIUSBRedirSession();
     JButton localJButton = null;
     DevicePanel localDevicePanel = null;
     switch (paramInt) {
     case 0: 
       if (!JViewer.isCdServiceEnabled())
         return;
       j = VMApp.getInstance().getNumCD();
       k = VMApp.getInstance().getFreeCDNum();
       break;
     case 1: 
       if (!JViewer.isFdServiceEnabled())
         return;
       j = VMApp.getInstance().getNumFD();
       k = VMApp.getInstance().getFreeFDNum();
       break;
     case 2: 
       if (!JViewer.isHdServiceEnabled())
         return;
       j = VMApp.getInstance().getNumHD();
       k = VMApp.getInstance().getFreeHDNum();
       break;
     default: 
       Debug.out.println("Invalid device type : " + paramInt);
     }
     
     for (int m = 0; m < j; m++) {
       localJButton = getDeviceControlPanel(paramInt, m).getConnectButton();
       localDevicePanel = getDeviceControlPanel(paramInt, m).getDevicePanel();
       
 
 
       if (localIUSBRedirSession.getDeviceRedirStatus(paramInt, m) != 1)
       {
 
         localDevicePanel.enableAll();
         localJButton.setEnabled(true);
         localIUSBRedirSession.setDeviceStatus(paramInt, m, 1);
         if (i < k)
         {
 
           i++;
 
 
 
         }
         else
         {
 
 
           localDevicePanel.disableAll();
           localJButton.setEnabled(false);
           localIUSBRedirSession.setDeviceStatus(paramInt, m, 0);
           localDevicePanel.revalidate();
           localDevicePanel.repaint();
         }
       }
     }
   }
   
 
   public StatusTabPanel getStatusTabPanel()
   {
     return this.statusTabPanel;
   }
   
 
   public void setStatusTabPanel(StatusTabPanel paramStatusTabPanel)
   {
     this.statusTabPanel = paramStatusTabPanel;
   }
   
   public void setSelectedTab(int paramInt) { this.vmDevicePane.setSelectedIndex(paramInt); }
   
   public JTabbedPane getVmDevicePane() {
     return this.vmDevicePane;
   }
   
   public void setVmDevicePane(JTabbedPane paramJTabbedPane) { this.vmDevicePane = paramJTabbedPane; }
   
 
 
 
   public void updateDeviceControls(int paramInt, boolean paramBoolean)
   {
     int i = 0;
     JButton localJButton = null;
     DevicePanel localDevicePanel = null;
     switch (paramInt) {
     case 0: 
       i = VMApp.getInstance().getNumCD();
       break;
     case 1: 
       i = VMApp.getInstance().getNumFD();
       break;
     case 2: 
       i = VMApp.getInstance().getNumHD();
       break;
     default: 
       Debug.out.println("Invalid device type : " + paramInt);
     }
     
     for (int j = 0; j < i; j++) {
       localJButton = getDeviceControlPanel(paramInt, j).getConnectButton();
       localDevicePanel = getDeviceControlPanel(paramInt, j).getDevicePanel();
       
 
 
       if (paramBoolean)
       {
         localDevicePanel.enableAll();
         localJButton.setEnabled(true);
 
 
 
       }
       else
       {
 
 
         localDevicePanel.disableAll();
         localJButton.setEnabled(false);
         
         localDevicePanel.revalidate();
         localDevicePanel.repaint();
       }
     }
   }
   
 
 
   public void showMessageForSelectedTab(int paramInt)
   {
     switch (paramInt)
     {
     case 0: 
       if (JViewer.getCDState() == 0) {
         VMApp.getVMStatusPanel().setStatusMessage(LocaleStrings.getString("G_27_VMD"));
       }
       else if (true == JViewer.IsClientAdmin()) {
         VMApp.getVMStatusPanel().setStatusMessage("");
       }
       else if (false == JViewer.IsClientAdmin()) {
         VMApp.getVMStatusPanel().setStatusMessage(LocaleStrings.getString("G_35_VMD"));
       }
       
       break;
     case 1: 
       if (JViewer.getFDState() == 0) {
         VMApp.getVMStatusPanel().setStatusMessage(LocaleStrings.getString("G_29_VMD"));
       }
       else if (true == JViewer.IsClientAdmin()) {
         VMApp.getVMStatusPanel().setStatusMessage("");
       }
       else if (false == JViewer.IsClientAdmin()) {
         VMApp.getVMStatusPanel().setStatusMessage(LocaleStrings.getString("G_35_VMD"));
       }
       
       break;
     case 2: 
       if (JViewer.getHDState() == 0) {
         VMApp.getVMStatusPanel().setStatusMessage(LocaleStrings.getString("G_31_VMD"));
       } else if (true == JViewer.IsClientAdmin()) {
         if ((JViewer.getOEMFeatureStatus() & 0x2) == 2L)
         {
           VMApp.getVMStatusPanel().setStatusMessage(LocaleStrings.getString("G_36_VMD"));
         }
         else {
           VMApp.getVMStatusPanel().setStatusMessage("");
         }
       }
       else if (false == JViewer.IsClientAdmin())
         VMApp.getVMStatusPanel().setStatusMessage(LocaleStrings.getString("G_35_VMD"));
       break;
     case 3: 
       VMApp.getVMStatusPanel().setStatusMessage("");
       break;
     default: 
       Debug.out.println("Invalid index : " + paramInt);
     }
   }
 }


/* Location:              D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\vmedia\gui\VMPane.class
 * Java compiler version: 5 (49.0)
 * JD-Core Version:       0.7.1
 */